import Vue from 'vue'
import axios from 'axios'
// import vueresource from 'vue-resource'
// Vue.use(vueresource)
let _service;

class Service{

    constructor(){
        axios.defaults.withCredentials = true;
        axios.defaults.timeout = 100000;
        axios.interceptors.request.use((config)=>{
            return config;
        },(error)=>{
            return Promise.reject(error);
        });
    }

    static instance(){
        if(_service === undefined)
            _service =  new Service();
        return _service;
    }

    get(url,param){
        return axios.get(url,param);
    }
    post(url,param){
        return axios({
            method: 'post',
            url: url,
            data: param,
            headers: {'Content-Type': 'application/json'},
        })
    }
    put(url,param){
        return axios.put(url,param,{headers:{'Content-Type':"application/json"}});
    }
    postBinary(url,param){
        return axios({
            method: 'post',
            url:url,
            data:param,
            headers: { 'Content-Type': 'multipart/form-data' },
            // onUploadProgress(progressEvent){
            //     if (progressEvent.lengthComputable) {
            //         var percentage = (progressEvent.loaded / progressEvent.total * 100).toFixed(0) + "%";
            //     }
            // }
        })
    }

}


export default Service
